<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <button>按钮1</button>
    <button>按钮2</button>
    <button>按钮3</button>
    <button>按钮4</button>
    <button>按钮5</button>

    <script>
        /* 
            需求：需要给每个按钮都绑定onclick事件
                  点击当前按钮的时候，把当前按钮的背景色为红色
                  其他按钮的颜色去掉
         */
        const btns = document.querySelectorAll("button")
        for (const btn of btns) {
            btn.onclick = function () {
                //先把所有按钮的样式进行初始化
                steAllbackgroundColor(btns)
                this.style.backgroundColor = 'red';

            }

            function steAllbackgroundColor(btn) {
                for (const btn of btns) {
                    btn.style.backgroundColor = '';
                }
            }
        }
    </script>
</body>

</html>